package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * 目标：
 *
 * @author Ashely
 * @date 2024/6/14 10:31
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    public static final String KEY_SHOP_STATUS = "SHOP_STATUS";
    @Autowired
    private RedisTemplate redisTemplate;
    @PutMapping("/{status}")
    @ApiOperation("修改店铺营业状态")
    public Result changeStatus(@PathVariable Integer status) {
        log.info("修改店铺营业状态:{}", status == 1 ? "开启" : "关闭");
        redisTemplate.opsForValue().set(KEY_SHOP_STATUS, status);

        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("查询店铺营业状态")
    public Result getStatus() {
        log.info("查询店铺营业状态");
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(KEY_SHOP_STATUS);
        return Result.success(shopStatus);
    }
}
